﻿(function ($) {

    $.extend($, {
        acl: {
            verbs: {
                enable: function (item, value) {
                    if (value)
                        item.enable();
                    else
                        item.disable();
                },
                visible: function (item, value) {
                    item.toggle(value);
                }
            }
        }
    });
    var oldtmpl = $.fn.tmpl;
    var refreshAcls = function () {
        this.find('[acl]').add(this.filter('[acl]')).each(function (index, item) {
            var $this = $(item);
            var resource = $this.attr('acl');
            for (var verb in $.acl.verbs) {
                $.acl.verbs[verb]($this, jAcl.isAllowed(resource, verb));
            }
        });
        return this;
    }
    $.extend($.fn, {
        refreshAcls: refreshAcls,
        acl: refreshAcls,
        tmpl: function (data, options) {
            return applyTemplate.call(oldtmpl.apply(this, arguments), data);
        }
    });
})(jQuery);